package com.func.boom.utils;

import com.func.boom.enums.ResultEnums;
import lombok.*;

/**
 * @author Yulei
 * @date 2020-08-13 19:26:50
 * @desc
 */
@Data
@NoArgsConstructor
public class ResultEntity<T> {

    public static ResultEntity success() {
        return new ResultEntity(ResultEnums.SUCCESS_REQUEST);
    }

    public static ResultEntity success(ResultEnums resultEnums) {
        return new ResultEntity(ResultEnums.SUCCESS_REQUEST, resultEnums);
    }

    public static <T> ResultEntity<T> success(T body) {
        return new ResultEntity<T>(ResultEnums.SUCCESS_REQUEST, ResultEnums.SUCCESS, body);
    }

    public static <T> ResultEntity<T> success(ResultEnums resultEnums, T body) {
        return new ResultEntity<T>(ResultEnums.SUCCESS_REQUEST, resultEnums, body);
    }

    public static ResultEntity error() {
        return new ResultEntity(ResultEnums.ERROR_REQUEST);
    }

    public static ResultEntity error(ResultEnums resultEnums) {
        return new ResultEntity(ResultEnums.ERROR_REQUEST, resultEnums);
    }

    public static <T> ResultEntity<T> error(ResultEnums resultEnums, T body) {
        return new ResultEntity<T>(ResultEnums.ERROR_REQUEST, resultEnums, body);
    }

    //返回状态 成功：200 失败：500
    private int status;
    //返回具体code
    private int code;
    //返回结果具体信息
    private String message;
    //泛型参数
    private T body;

    public ResultEntity(int status) {
        this.status = status;
    }
    
    public ResultEntity(int status, ResultEnums resultEnums) {
        this.status = status;
        this.code = resultEnums.getCode();
        this.message = resultEnums.getMessage();
    }

    public ResultEntity(int status, ResultEnums resultEnums, T body) {
        this.status = status;
        this.code = resultEnums.getCode();
        this.message = resultEnums.getMessage();
        this.body = body;
    }
    
}
